package com.hotel.web.controller.hotel;

import com.hotel.common.core.controller.BaseController;
import com.hotel.common.core.domain.AjaxResult;
import com.hotel.common.core.page.TableDataInfo;
import com.hotel.system.domain.hotel.Order;
import com.hotel.system.service.OrderService;
import com.hotel.system.service.RoomService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 酒店房间信息操作处理
 * 
 * @author hotel
 */
@Controller
@RequestMapping("/hotel/order")
public class OrderController extends BaseController
{
    private String prefix = "hotel/order/";

    @Autowired
    private OrderService orderService;

    @Autowired
    private RoomService roomService;

    @RequiresPermissions("hotel:order:view")
    @GetMapping()
    public String order()
    {

        return prefix + "order";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Order order)
    {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    @RequiresPermissions("hotel:order:add")
    @GetMapping("/add")
    public String addOrder(ModelMap mmap)
    {
        return prefix + "add";
    }

    @RequiresPermissions("hotel:order:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated Order order) {

        return toAjax( orderService.insertOrder(order));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("order", orderService.selectOrderId(id));
        return prefix + "edit";
    }

    /**
     * 出库入库调整
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editOrder(@Validated Order order)
    {
        return toAjax(orderService.updateOrder(order));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderService.updateOrderStatus(ids));
    }




}
